package com.gym.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.gym.dao.EquipmentupkeepDao;
import com.gym.pojo.Equipmentupkeep;
import com.gym.service.EquipmentupkeepService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional
public class EquipmentupkeepServiceImpl implements EquipmentupkeepService {

    @Resource
    private EquipmentupkeepDao equipmentupkeepDao;

    /*
     * 查询全部器材维修信息
     * */
    @Override
    public List<Equipmentupkeep> selAllUpKeep(Integer pageIndex,String equname,String start, String end) {
        Page<Equipmentupkeep> page = PageHelper.startPage(pageIndex,5);
        equipmentupkeepDao.selAllUpKeep(equname,start,end);
        return page.getResult();
    }

    /*
     * 查询全部器材维修信息数量
     * */
    @Override
    public Integer selRepairCount(String equname, String start, String end) {
        return equipmentupkeepDao.selRepairCount(equname, start, end);
    }

    /**
     * 添加器材维修信息
     * @param equipmentupkeep
     * @return
     */
    @Override
    public boolean addEquRepair(Equipmentupkeep equipmentupkeep) {
        return equipmentupkeepDao.addEquRepair(equipmentupkeep)>0;
    }

    /*
     * 修改器材维修信息
     * */
    @Override
    public boolean updateEquRepair(Equipmentupkeep equipmentupkeep) {
        return equipmentupkeepDao.updateEquRepair(equipmentupkeep)>0;
    }


    /*
     * 删除器材维修信息
     * */
    @Override
    public boolean delEquRepair(String equkeepid) {
        String[] str = equkeepid.split("-");
        boolean flag = false;

        for (String s:str) {
            Integer i = Integer.parseInt(s);
            flag = equipmentupkeepDao.delEquRepair(i)>0;
        }
        return flag;
    }

}
